package com.kabuda.hot100.二叉树.easy;

import com.kabuda.hot100.二叉树.TreeNode;

/**
 * @author kabuda
 * @date 2025-03-08 17:18
 * @description 给定一个二叉树 root ，返回其最大深度。
 * <p>
 * 二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。
 */
public class t104_二叉树的最大深度 {
    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(3);
        TreeNode treeNode2 = new TreeNode(9);
        TreeNode treeNode3 = new TreeNode(20);
        TreeNode treeNode4 = new TreeNode(15);
        TreeNode treeNode5 = new TreeNode(7);
        treeNode1.left = treeNode2;
        treeNode1.right= treeNode3;
        treeNode3.left= treeNode4;
        treeNode3.right= treeNode5;
        System.out.println(maxDepth(treeNode1));
    }

    public static int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;

    }




}
